4
4
def test_bool_lin ():
5
5
f = pindakaas .CNF ()
6
6
x , y , z = f .new_vars (3 )
7
- c = x + y - z + 2
8
- assert str (c ) == "-x₃ + x₂ + x₁ + 2"
9
- c = sum ([y , y , z ], x )
10
- assert str (c ) == "x₃ + x₂ + x₂ + x₁"
7
+ assert str (x + 2 ) == "x₁ + 2" , "__add__ incorrect"
8
+ assert str (2 + x ) == "x₁ + 2" , "__radd__ incorrect"
9
+ assert str (x - 2 ) == "x₁ + -2" , "__sub__ incorrect"
10
+ assert str (2 * x ) == "2*x₁" , "__mul__ incorrect"
11
+ assert str (x * 2 ) == "2*x₁" , "__rmul__ incorrect"
12
+ assert str (x + y - z + 2 ) == "-x₃ + x₂ + x₁ + 2"
13
+ c = sum ([x , y , z ])
14
+ assert str (c ) == "x₃ + x₂ + x₁"
11
15
c *= 2
12
- assert str (c ) == "2*x₃ + 2*x₂ + 2*x₂ + 2*x ₁"
16
+ assert str (c ) == "2*x₃ + 2*x₂ + 2*x₁"
13
17
c = x + y + z
14
18
d = c == 2
15
19
assert str (d ) == "x₃ + x₂ + x₁ == 2"
@@ -18,17 +22,43 @@ def test_bool_lin():
18
22
d = c >= 2
19
23
assert str (d ) == "x₃ + x₂ + x₁ >= 2"
20
24
25
+ def test_bool_lin_ops ():
26
+ f = pindakaas .CNF ()
27
+ x , y , z = f .new_vars (3 )
28
+ f = x + y
29
+ g = x - z
30
+ assert str (f + 2 ) == "x₂ + x₁ + 2" , "__add__ incorrect"
31
+ assert str (2 + f ) == "x₂ + x₁ + 2" , "__radd__ incorrect"
32
+ assert str (f + g ) == "-x₃ + x₁ + x₂ + x₁" , "__add__ incorrect"
33
+ assert str (f * 2 ) == "2*x₂ + 2*x₁" , "__mul__ incorrect"
34
+ assert str (2 * f ) == "2*x₂ + 2*x₁" , "__rmul__ incorrect"
21
35
22
- def test_lit_ops ():
36
+ def test_formula_ops ():
23
37
f = pindakaas .CNF ()
24
38
x , y , z = f .new_vars (3 )
25
- a = ~ x | ~ y
26
- assert str (a ) == "¬x₁ ∨ ¬x₂"
27
- b = y & z
28
- assert str (b ) == "x₂ ∧ x₃"
29
- c = x ^ y
30
- assert str (c ) == "x₁ ⊻ x₂"
31
- d = x ^ True
32
- assert str (d ) == "x₁ ⊻ true"
33
- e = x == y
34
- assert str (e ) == "x₁ ≡ x₂"
39
+ f = x & y
40
+ g = x | z
41
+ assert str (f & True ) == "x₁ ∧ x₂ ∧ true" , "__and__ incorrect"
42
+ assert str (True & f ) == "x₁ ∧ x₂ ∧ true" , "__rand__ incorrect"
43
+ assert str (f & g ) == "x₁ ∧ x₂ ∧ (x₁ ∨ x₃)" , "__and__ incorrect"
44
+ assert str (f | True ) == "(x₁ ∧ x₂) ∨ true" , "__or__ incorrect"
45
+ assert str (True | f ) == "(x₁ ∧ x₂) ∨ true" , "__ror__ incorrect"
46
+ assert str (f | g ) == "x₁ ∨ x₃ ∨ (x₁ ∧ x₂)" , "__or__ incorrect"
47
+ assert str (f ^ True ) == "(x₁ ∧ x₂) ⊻ true" , "__xor__ incorrect"
48
+ assert str (True ^ f ) == "(x₁ ∧ x₂) ⊻ true" , "__rxor__ incorrect"
49
+ assert str (f ^ g ) == "(x₁ ∧ x₂) ⊻ (x₁ ∨ x₃)" , "__xor__ incorrect"
50
+
51
+ def test_lit_ops ():
52
+ f = pindakaas .CNF ()
53
+ x , y = f .new_vars (2 )
54
+ assert str (x & True ) == "x₁ ∧ true" , "__and__ incorrect"
55
+ assert str (True & x ) == "x₁ ∧ true" , "__rand__ incorrect"
56
+ assert str (x | True ) == "x₁ ∨ true" , "__or__ incorrect"
57
+ assert str (True | x ) == "x₁ ∨ true" , "__ror__ incorrect"
58
+ assert str (x ^ True ) == "x₁ ⊻ true" , "__xor__ incorrect"
59
+ assert str (True ^ x ) == "x₁ ⊻ true" , "__rxor__ incorrect"
60
+ assert str (~ x | ~ y ) == "¬x₁ ∨ ¬x₂"
61
+ assert str (x & y ) == "x₁ ∧ x₂"
62
+ assert str (x ^ y ) == "x₁ ⊻ x₂"
63
+ assert str (x == y ) == "x₁ ≡ x₂"
64
+
0 commit comments